/**
 * Created by Jie on 2017/1/14.
 */
//自动编号
Handlebars.registerHelper("format_index",function(index){
    //返回+1之后的结果
    return index+1;
});
//项目类型 0通用 1App 2PC 3Web 4硬件/物联网 5其他
Handlebars.registerHelper("format_proj_type", function(value) {
    switch(value)
    {
        case 0:
            return "通用";
            break;
        case 1:
            return "App";
            break;
        case 2:
            return "PC";
            break;
        case 3:
            return "Web";
            break;
        case 4:
            return "硬件/物联网";
            break;
        case 5:
            return "其他";
            break;
        default:
            return "未知";
    }
});
function format_proj_type(_value){
    var type ="";
    switch(_value)
    {
        case 0:
            type = "通用";
            break;
        case 1:
            type = "App";
            break;
        case 2:
            type = "PC";
            break;
        case 3:
            type = "Web";
            break;
        case 4:
            type = "硬件/物联网";
            break;
        case 5:
            type = "其他";
            break;
        default:
            type = "未知";
            break;
    }
    return type;
}
//性别格式化
Handlebars.registerHelper("format_sex", function(value) {
    if (value == 1) {
        return "男";
    } else if (value == 0) {
        return "女";
    }
});
//时间戳转成短时间格式
Handlebars.registerHelper("format_short_date",function(value){
    if (value == "" || value == null || value == 0) {
        return "";
    } else {
        var $date = new Date(parseInt(value) * 1000);
        var $short_date = $date.getFullYear()+"/"+($date.getMonth()+1)+"/"+$date.getDate();
        return $short_date;
    }
})
//判断是否为null
Handlebars.registerHelper("format_null",function(value){
    if (value == "null" || value == null) {
        return "";
    } else {
        return value;
    }
})
//时间戳转成时间格式
Handlebars.registerHelper("format_date",function(value){
    if (value == "" || value == null || value == 0) {
        return "";
    } else {
        var date = new Date(parseInt(value) * 1000);
        var Y = date.getFullYear() + '-';
        var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
        var D = date.getDate() + ' ';
        var h = date.getHours() + ':';
        var m = date.getMinutes() + ':';
        var s = date.getSeconds();
        return (Y+M+D+h+m+s);
    }
})
function format_date(_value) {
    if (_value == "" || _value == null || _value == 0) {
        return "";
    } else {
        var date = new Date(parseInt(_value) * 1000);
        var Y = date.getFullYear() + '-';
        var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
        var D = date.getDate() + ' ';
        var h = date.getHours() + ':';
        var m = date.getMinutes() + ':';
        var s = date.getSeconds();
        return (Y+M+D+h+m+s);
    }
}
//请求类型格式化 1POST 2GET 3PUT 4DELETE 5PATCH 6OPTIONS
Handlebars.registerHelper("format_method", function(value) {
    switch(value)
    {
        case 1:
            return "POST";
            break;
        case 2:
            return "GET";
            break;
        case 3:
            return "PUT";
            break;
        case 4:
            return "DELETE";
            break;
        case 5:
            return "PATCH";
            break;
        case 6:
            return "OPTIONS";
            break;
        default:
            return "未知"
            break;
    }
});
function format_method(_value) {
    switch(_value)
    {
        case 1:
            return "POST";
            break;
        case 2:
            return "GET";
            break;
        case 3:
            return "PUT";
            break;
        case 4:
            return "DELETE";
            break;
        case 5:
            return "PATCH";
            break;
        case 6:
            return "OPTIONS";
            break;
        default:
            return "未知"
            break;
    }
}
//请求类型背景色格式化
Handlebars.registerHelper("format_method_bg", function(value) {
    switch(value)
    {
        case 1:
            return "mdui-color-indigo-a700";
            break;
        case 2:
            return "mdui-color-purple-700";
            break;
        case 3:
            return "mdui-color-green-700";
            break;
        case 4:
            return "mdui-color-red-a700";
            break;
        case 5:
            return "mdui-color-brown-700";
            break;
        case 6:
            return "mdui-color-blue-grey-700";
            break;
        default:
            return "未知"
            break;
    }
});
//接口状态 1启用 2维护 3停用
Handlebars.registerHelper("format_api_status", function(value) {
    switch(value)
    {
        case 1:
            return "启用";
            break;
        case 2:
            return "维护";
            break;
        case 3:
            return "停用";
            break;
        default:
            return "未知"
            break;
    }
});
//请求返回码
Handlebars.registerHelper("format_http_code", function(value) {
    switch(value)
    {
        case 200:
            return " mdui-color-blue ";
            break;
        case 500:
            return "mdui-color-pink-accent ";
            break;
        default:
            return "mdui-color-purple-700 "
            break;
    }
});
//操作类型 1新增 2修改 3删除 0无状态
Handlebars.registerHelper("format_op", function(value) {
    switch(value)
    {
        case 1:
            return "新增";
            break;
        case 2:
            return "修改";
            break;
        case 3:
            return "删除";
            break;
        default:
            return "无状态"
            break;
    }
});